package com.lmiot.xyclick.Util;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.IfBean;
import com.lmiot.xyclick.Bean.SQL.ActionBean;
import com.lmiot.xyclick.Bean.SQL.ActionBeanSqlUtil;
import com.lmiot.xyclick.Bean.SQL.AutoBean;
import com.lmiot.xyclick.Bean.SQL.AutoBeanSqlUtil;
import com.lmiot.xyclick.Method.CheckIfAction;
import com.lmiot.xyclick.Util.RecordSDK;
import com.lmiot.xyclick.Util.ZipUtilOld;
import com.xiaoyi.pdocrlibrary.OCRResultBean;
import com.xiaoyi.pdocrlibrary.PaddOCRSDK;
import com.youyi.yychosesdk.utils.file.FileUtils;
import com.youyi.yypermissionlibrary.SDK.YYPerUtils;
import com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK;
import com.youyi.yyscreencutlibrary.Track.YYTrackSDK;
import com.youyi.yyviewsdklibrary.ArrayGson;
import com.youyi.yyviewsdklibrary.Dialog.util.ToastUtil;
import java.io.File;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class LoopUtils {
    private static final String TAG = "LoopUtils";
    private static boolean colorResult = false;
    private static File fileFolder = null;
    public static boolean hasStartRecord = false;
    private static boolean isRunning = false;
    private static boolean judgeResult = false;
    private static Bitmap mFullBitmap = null;
    private static String mImgPath = null;
    private static String mImgPathRect = null;
    public static RecordSDK.OnRecordListener mOnRecordListener = null;
    private static String mRGB = null;
    private static Bitmap mRectBitmap = null;
    private static String mZipPath = null;
    private static Handler mhandler = null;
    private static boolean resultDistance = false;
    private static Runnable runnable = null;
    private static List<OCRResultBean> textBeanList = null;
    private static boolean unZipFinish = false;

    public interface onUnZipFinishListener {
        void result(boolean z);
    }

    public interface onZipFinishListener {
        void result(String str);
    }

    public static Bitmap trackFull() {
        try {
            mFullBitmap = null;
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass1 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    if (YYTrackSDK.getInstance().isRecording()) {
                        long currentTimeMillis = System.currentTimeMillis();
                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启");
                        Bitmap unused = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 50);
                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis));
                        if (LoopUtils.mFullBitmap != null) {
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！" + LoopUtils.mFullBitmap);
                        }
                        LoopUtils.quitLoop();
                    } else {
                        final long currentTimeMillis2 = System.currentTimeMillis();
                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启");
                        YYTrackSDK.getInstance().startRecording(MyApp.getContext(), new YYTrackSDK.OnStrartRecordListener() {

                            @Override
                            public void result(boolean z, String str) {
                                LogUtil.d(LoopUtils.TAG, "录屏的方式找图:回调了");
                                if (z) {
                                    Bitmap unused = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                    LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis2));
                                    if (LoopUtils.mFullBitmap != null) {
                                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！");
                                    }
                                }
                                LoopUtils.quitLoop();
                            }
                        });
                    }
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return mFullBitmap;
        } catch (Exception e) {
            e.printStackTrace();
            return mFullBitmap;
        } catch (Throwable unused) {
            return mFullBitmap;
        }
    }

    public static Bitmap cutFull() {
        if (DataUtil.getTrackImg(MyApp.getContext()) || Build.VERSION.SDK_INT >= 34) {
            try {
                mFullBitmap = null;
                Thread mThread = new Thread() {
                    public void run() {
                        LoopUtils.setLoopPrepare();
                        if (YYTrackSDK.getInstance().isRecording()) {
                            long currentTimeMillis = System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启");
                            Bitmap unused = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis));
                            if (LoopUtils.mFullBitmap != null) {
                                LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！" + LoopUtils.mFullBitmap);
                            }
                            LoopUtils.quitLoop();
                        } else {
                            final long currentTimeMillis2 = System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启");
                            YYTrackSDK.getInstance().startRecording(MyApp.getContext(), new YYTrackSDK.OnStrartRecordListener() {
                                @Override
                                public void result(boolean z, String str) {
                                    LogUtil.d(LoopUtils.TAG, "录屏的方式找图:startRecording result: str"+str+",z:"+z);
                                    if (z) {
                                        if (YYPerUtils.isXiaoMi()) {
                                            try {
                                                Thread.sleep(1200);
                                            } catch (Exception unused) {
                                            }
                                        }
                                        Bitmap unused2 = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                        if (LoopUtils.mFullBitmap == null) {
                                            for (int i = 0; i < 10; i++) {
                                                LogUtil.d(LoopUtils.TAG, "录屏的方式找图:获取次数=" + i);
                                                Bitmap unused3 = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                                if (LoopUtils.mFullBitmap != null) {
                                                    break;
                                                }
                                                try {
                                                    Thread.sleep(500);
                                                } catch (InterruptedException unused4) {
                                                }
                                            }
                                        }
                                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis2));
                                        if (LoopUtils.mFullBitmap != null) {
                                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！");
                                        }
                                    }
                                    LoopUtils.quitLoop();
                                }
                            });
                        }
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mFullBitmap;
            } catch (Exception e) {
                e.printStackTrace();
                return mFullBitmap;
            } catch (Throwable unused) {
                return mFullBitmap;
            }
        } else {
            try {
                mFullBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass3 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        YYScreenCutSDK.getInstance().cutFull(MyApp.getContext(), new YYScreenCutSDK.OnCutListener() {
                            @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                            public void result(boolean z, Bitmap bitmap) {
                                if (z) {
                                    Bitmap unused = LoopUtils.mFullBitmap = bitmap;
                                }
                                LoopUtils.quitLoop();
                            }
                        });
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mFullBitmap;
            } catch (Exception e2) {
                e2.printStackTrace();
                return mFullBitmap;
            } catch (Throwable unused2) {
                return mFullBitmap;
            }
        }
    }

    public static Bitmap cutRect(final Rect rect) {
        if (DataUtil.getTrackImg(MyApp.getContext()) || Build.VERSION.SDK_INT >= 34) {
            try {
                mRectBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass4 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        if (YYTrackSDK.getInstance().isRecording()) {
                            System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启");
                            Bitmap bitmapPress = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                            if (bitmapPress != null) {
                                Bitmap unused = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitmapPress, rect.left, rect.top, rect.width(), rect.height());
                            }
                            LoopUtils.quitLoop();
                        } else {
                            System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启");
                            YYTrackSDK.getInstance().startRecording(MyApp.getContext(), new YYTrackSDK.OnStrartRecordListener() {
                                @Override // com.youyi.yyscreencutlibrary.Track.YYTrackSDK.OnStrartRecordListener
                                public void result(boolean z, String str) {
                                    if (z) {
                                        if (YYPerUtils.isXiaoMi()) {
                                            try {
                                                Thread.sleep(1200);
                                            } catch (Exception unused) {
                                            }
                                        }
                                        Bitmap bitmapPress = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                        if (bitmapPress != null) {
                                            Bitmap unused2 = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitmapPress, rect.left, rect.top, rect.width(), rect.height());
                                        }
                                    }
                                    LoopUtils.quitLoop();
                                }
                            });
                        }
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mRectBitmap;
            } catch (Exception e) {
                e.printStackTrace();
                return mRectBitmap;
            } catch (Throwable unused) {
                return mRectBitmap;
            }
        } else {
            try {
                mRectBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass5 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        YYScreenCutSDK.getInstance().cutRect(MyApp.getContext(), rect, new YYScreenCutSDK.OnCutListener() {
                            @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                            public void result(boolean z, Bitmap bitmap) {
                                Bitmap bitMap;
                                if (z && (bitMap = YYTrackSDK.getInstance().getBitMap()) != null) {
                                    Bitmap unused = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitMap, rect.left, rect.top, rect.width(), rect.height());
                                }
                                LoopUtils.quitLoop();
                            }
                        });
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mRectBitmap;
            } catch (Exception e2) {
                e2.printStackTrace();
                return mRectBitmap;
            } catch (Throwable unused2) {
                return mRectBitmap;
            }
        }
    }

    public static Bitmap cutFull000() {
        if (DataUtil.getTrackImg(MyApp.getContext()) || Build.VERSION.SDK_INT >= 34) {
            try {
                mFullBitmap = null;
                Thread mThread = new Thread() {
                    public void run() {
                        LoopUtils.setLoopPrepare();
                        if (YYTrackSDK.getInstance().isRecording()) {
                            long currentTimeMillis = System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启");
                            Bitmap unused = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis));
                            if (LoopUtils.mFullBitmap != null) {
                                LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！" + LoopUtils.mFullBitmap);
                            }
                            LoopUtils.quitLoop();
                        } else {
                            final long currentTimeMillis2 = System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启");
                            YYTrackSDK.getInstance().startRecording(MyApp.getContext(), new YYTrackSDK.OnStrartRecordListener() {
                                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass6.AnonymousClass1 */

                                @Override // com.youyi.yyscreencutlibrary.Track.YYTrackSDK.OnStrartRecordListener
                                public void result(boolean z, String str) {
                                    if (z) {
                                        if (YYPerUtils.isXiaoMi()) {
                                            try {
                                                Thread.sleep(1200);
                                            } catch (Exception unused) {
                                            }
                                        }
                                        Bitmap unused2 = LoopUtils.mFullBitmap = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                        LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启：找图成功:" + (System.currentTimeMillis() - currentTimeMillis2));
                                        if (LoopUtils.mFullBitmap != null) {
                                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:bitMap不为空！");
                                        }
                                    }
                                    LoopUtils.quitLoop();
                                }
                            });
                        }
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mFullBitmap;
            } catch (Exception e) {
                e.printStackTrace();
                return mFullBitmap;
            } catch (Throwable unused) {
                return mFullBitmap;
            }
        } else {
            try {
                mFullBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass7 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        YYScreenCutSDK.getInstance().cutFull(MyApp.getContext(), new YYScreenCutSDK.OnCutListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass7.AnonymousClass1 */

                            @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                            public void result(boolean z, Bitmap bitmap) {
                                if (z) {
                                    Bitmap unused = LoopUtils.mFullBitmap = bitmap;
                                }
                                LoopUtils.quitLoop();
                            }
                        });
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mFullBitmap;
            } catch (Exception e2) {
                e2.printStackTrace();
                return mFullBitmap;
            } catch (Throwable unused2) {
                return mFullBitmap;
            }
        }
    }

    public static Bitmap cutRect000(final Rect rect) {
        if (DataUtil.getTrackImg(MyApp.getContext()) || Build.VERSION.SDK_INT >= 34) {
            try {
                mRectBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass8 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        if (YYTrackSDK.getInstance().isRecording()) {
                            System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000不用重新开启");
                            Bitmap bitmapPress = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                            if (bitmapPress != null) {
                                Bitmap unused = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitmapPress, rect.left, rect.top, rect.width(), rect.height());
                            }
                            LoopUtils.quitLoop();
                        } else {
                            System.currentTimeMillis();
                            LogUtil.d(LoopUtils.TAG, "录屏的方式找图:0000000000000000重新开启");
                            YYTrackSDK.getInstance().startRecording(MyApp.getContext(), new YYTrackSDK.OnStrartRecordListener() {
                                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass8.AnonymousClass1 */

                                @Override // com.youyi.yyscreencutlibrary.Track.YYTrackSDK.OnStrartRecordListener
                                public void result(boolean z, String str) {
                                    if (z) {
                                        if (YYPerUtils.isXiaoMi()) {
                                            try {
                                                Thread.sleep(1200);
                                            } catch (Exception unused) {
                                            }
                                        }
                                        Bitmap bitmapPress = ImgUtil.bitmapPress(YYTrackSDK.getInstance().getBitMap(), 90);
                                        if (bitmapPress != null) {
                                            Bitmap unused2 = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitmapPress, rect.left, rect.top, rect.width(), rect.height());
                                        }
                                    }
                                    LoopUtils.quitLoop();
                                }
                            });
                        }
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mRectBitmap;
            } catch (Exception e) {
                e.printStackTrace();
                return mRectBitmap;
            } catch (Throwable unused) {
                return mRectBitmap;
            }
        } else {
            try {
                mRectBitmap = null;
                Thread mThread = new Thread() {
                    /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass9 */

                    public void run() {
                        LoopUtils.setLoopPrepare();
                        YYScreenCutSDK.getInstance().cutRect(MyApp.getContext(), rect, new YYScreenCutSDK.OnCutListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass9.AnonymousClass1 */

                            @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                            public void result(boolean z, Bitmap bitmap) {
                                Bitmap bitMap;
                                if (z && (bitMap = YYTrackSDK.getInstance().getBitMap()) != null) {
                                    Bitmap unused = LoopUtils.mRectBitmap = Bitmap.createBitmap(bitMap, rect.left, rect.top, rect.width(), rect.height());
                                }
                                LoopUtils.quitLoop();
                            }
                        });
                        Looper.loop();
                    }
                };
                mThread.start();
                mThread.join();
                return mRectBitmap;
            } catch (Exception e2) {
                e2.printStackTrace();
                return mRectBitmap;
            } catch (Throwable unused2) {
                return mRectBitmap;
            }
        }
    }

    public static String getColorByXY(final int i, final int i2) {
        try {
            mRGB = "";
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass10 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    YYScreenCutSDK.getInstance().cutFull(MyApp.getContext(), new YYScreenCutSDK.OnCutListener() {
                        /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass10.AnonymousClass1 */

                        @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                        public void result(boolean z, Bitmap bitmap) {
                            String unused = LoopUtils.mRGB = YYScreenCutSDK.getColorByXY(bitmap, i, i2, true);
                            LoopUtils.quitLoop();
                        }
                    });
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return mRGB;
        } catch (Exception e) {
            e.printStackTrace();
            return mRGB;
        } catch (Throwable unused) {
            return mRGB;
        }
    }

    public static boolean hasColor(Bitmap bitmap, String str) {
        if (str.contains("#")) {
            str = str.replaceAll("#", "");
        }
        if (bitmap == null) {
            return false;
        }
        boolean z = false;
        for (int i = 0; i < bitmap.getHeight(); i++) {
            int i2 = 0;
            while (true) {
                if (i2 >= bitmap.getWidth()) {
                    break;
                }
                int pixel = bitmap.getPixel(i2, i);
                String hexString = Integer.toHexString(Color.red(pixel));
                String hexString2 = Integer.toHexString(Color.green(pixel));
                String hexString3 = Integer.toHexString(Color.blue(pixel));
                if (hexString.length() == 1) {
                    hexString = "0" + hexString;
                }
                if (hexString2.length() == 1) {
                    hexString2 = "0" + hexString2;
                }
                if (hexString3.length() == 1) {
                    hexString3 = "0" + hexString3;
                }
                if (str.equals((hexString + hexString2 + hexString3).toUpperCase())) {
                    z = true;
                    break;
                }
                i2++;
            }
        }
        return z;
    }

    public static boolean judgeColorByFull(final String str) {
        try {
            colorResult = false;
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass11 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    YYScreenCutSDK.getInstance().cutFull(MyApp.getContext(), new YYScreenCutSDK.OnCutListener() {
                        /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass11.AnonymousClass1 */

                        @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                        public void result(boolean z, Bitmap bitmap) {
                            boolean unused = LoopUtils.colorResult = LoopUtils.hasColor(bitmap, str);
                            LoopUtils.quitLoop();
                        }
                    });
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return colorResult;
        } catch (Exception e) {
            e.printStackTrace();
            return colorResult;
        } catch (Throwable unused) {
            return colorResult;
        }
    }

    public static boolean judgeColorByRect(final String str, final Rect rect) {
        try {
            colorResult = false;
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass12 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    YYScreenCutSDK.getInstance().cutByData(MyApp.getContext(), rect, new YYScreenCutSDK.OnCutListener() {
                        /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass12.AnonymousClass1 */

                        @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                        public void result(boolean z, Bitmap bitmap) {
                            boolean unused = LoopUtils.colorResult = LoopUtils.hasColor(bitmap, str);
                            LoopUtils.quitLoop();
                        }
                    });
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return colorResult;
        } catch (Exception e) {
            e.printStackTrace();
            return colorResult;
        } catch (Throwable unused) {
            return colorResult;
        }
    }

    public static boolean judgeColorListByRect(final List<String> list, final Rect rect) {
        try {
            colorResult = false;
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass13 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    YYScreenCutSDK.getInstance().cutByData(MyApp.getContext(), rect, new YYScreenCutSDK.OnCutListener() {
                        /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass13.AnonymousClass1 */

                        @Override // com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK.OnCutListener
                        public void result(boolean z, Bitmap bitmap) {
                            boolean z2;
                            Iterator it = list.iterator();
                            while (true) {
                                if (it.hasNext()) {
                                    if (LoopUtils.hasColor(bitmap, (String) it.next())) {
                                        z2 = true;
                                        break;
                                    }
                                } else {
                                    z2 = false;
                                    break;
                                }
                            }
                            boolean unused = LoopUtils.colorResult = z2;
                            LoopUtils.quitLoop();
                        }
                    });
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return colorResult;
        } catch (Exception e) {
            e.printStackTrace();
            return colorResult;
        } catch (Throwable unused) {
            return colorResult;
        }
    }

    public static boolean judgeAciton(final IfBean ifBean) {
        LogUtil.d(TAG, new Gson().toJson(ifBean));
        try {
            judgeResult = false;
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass14 */

                public void run() {
                    CheckIfAction.getInstance().check( ifBean ,new CheckIfAction.OnResultListener() {
                        @Override // com.lmiot.xyclick.Method.CheckIfAction.OnResultListener
                        public void result(boolean z) {
                            LogUtil.d(LoopUtils.TAG, "isMatch:" + z);
                            boolean unused = LoopUtils.judgeResult = z;
                        }
                    });
                }
            };
            mThread.start();
            mThread.join();
            return judgeResult;
        } catch (Exception e) {
            e.printStackTrace();
            return judgeResult;
        } catch (Throwable unused) {
            return judgeResult;
        }
    }

    public static List<OCRResultBean> OCRTextByTargetText(Bitmap bitmap, String str) {
        ArrayList arrayList = new ArrayList();
        List<OCRResultBean> localOCRText = localOCRText(bitmap);
        if (localOCRText != null && localOCRText.size() > 0) {
            for (OCRResultBean oCRResultBean : localOCRText) {
                if (TextUtils.isEmpty(str)) {
                    arrayList.add(oCRResultBean);
                } else if (oCRResultBean.getWord().equals(str) || oCRResultBean.getWord().contains(str)) {
                    arrayList.add(oCRResultBean);
                }
            }
        }
        return arrayList;
    }

    private static List<OCRResultBean> localOCRText(final Bitmap bitmap) {
        try {
            textBeanList = new ArrayList();
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass15 */

                public void run() {
                    LoopUtils.setLoopPrepare();
                    if (Build.VERSION.SDK_INT >= 23) {
                        PaddOCRSDK.getInstance().resloveBitmap(bitmap, new PaddOCRSDK.OnOcrResultListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass15.AnonymousClass1 */

                            @Override // com.xiaoyi.pdocrlibrary.PaddOCRSDK.OnOcrResultListener
                            public void result(boolean z, String str, int i, String str2, Bitmap bitmap, List<OCRResultBean> list) {
                                if (z) {
                                    LogUtil.d(LoopUtils.TAG, "本地OCR识别成功:" + str2);
                                } else {
                                    LogUtil.d(LoopUtils.TAG, "本地OCR识别失败！");
                                }
                                List unused = LoopUtils.textBeanList = list;
                                LoopUtils.quitLoop();
                            }
                        });
                    } else {
                        List unused = LoopUtils.textBeanList = new ArrayList();
                        LoopUtils.quitLoop();
                    }
                    Looper.loop();
                }
            };
            mThread.start();
            mThread.join();
            return textBeanList;
        } catch (Exception e) {
            e.printStackTrace();
            return textBeanList;
        } catch (Throwable unused) {
            return textBeanList;
        }
    }

    public static String strToMD5(String str) {
        String str2 = new String();
        try {
            MessageDigest instance = MessageDigest.getInstance("MD5");
            instance.update(str.getBytes());
            byte[] digest = instance.digest();
            StringBuffer stringBuffer = new StringBuffer("");
            for (byte b : digest) {
                int i = b;
                if (b < 0) {
                    i = b + 256;
                }
                if (i < 16) {
                    stringBuffer.append("0");
                }
                stringBuffer.append(Integer.toHexString(i == 1 ? 1 : 0));
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return str2;
        }
    }

    public static void unZipBackFile(final File file, final onUnZipFinishListener onunzipfinishlistener) {
        try {
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass16 */

                public void run() {
                    try {
                        com.lmiot.xyclick.Util.FileUtils.checkFolder();
                        ZipUtilOld.upZipFile(file, new File(Environment.getExternalStorageDirectory() + "/XYClick").getAbsolutePath(), new ZipUtilOld.UnZipListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass16.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.Util.ZipUtilOld.UnZipListener
                            public void result(boolean z) {
                                try {
                                    if (onunzipfinishlistener != null) {
                                        onunzipfinishlistener.result(true);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mThread.start();
            mThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void unZipAuto(final String str, final File file, final onUnZipFinishListener onunzipfinishlistener) {
        try {
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass17 */

                public void run() {
                    try {
                        File unused = LoopUtils.fileFolder = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp");
                        ZipUtilOld.upZipFile(file, LoopUtils.fileFolder.getAbsolutePath(), new ZipUtilOld.UnZipListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass17.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.Util.ZipUtilOld.UnZipListener
                            public void result(boolean z) {
                                File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + "." + DataUtil.FILE_ACTION_DATA);
                                if (file.exists()) {
                                    ActionBeanSqlUtil.getInstance().addList01(new ArrayGson().fromJsonList(FileUtils.readFileToString(file), ActionBean.class));
                                }
                                File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp", str + "." + DataUtil.FILE_AUTO_DATA);
                                if (file2.exists()) {
                                    AutoBeanSqlUtil.getInstance().add((AutoBean) new Gson().fromJson(FileUtils.readFileToString(file2), AutoBean.class));
                                }
                                if (onunzipfinishlistener != null) {
                                    onunzipfinishlistener.result(true);
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mThread.start();
            mThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void unZipAll(final File file, final onUnZipFinishListener onunzipfinishlistener) {
        try {
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass18 */

                public void run() {
                    try {
                        File unused = LoopUtils.fileFolder = new File(Environment.getExternalStorageDirectory() + "/XYClick/data");
                        ZipUtilOld.upZipFile(file, LoopUtils.fileFolder.getAbsolutePath(), new ZipUtilOld.UnZipListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass18.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.Util.ZipUtilOld.UnZipListener
                            public void result(boolean z) {
                                try {
                                    if (onunzipfinishlistener != null) {
                                        onunzipfinishlistener.result(true);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mThread.start();
            mThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    public static void setLoopPrepare() {
        isRunning = true;
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
        mhandler = new Handler(Looper.myLooper());
        startTimerOut();
    }

    /* access modifiers changed from: private */
    public static void quitLoop() {
        isRunning = false;
        mhandler.getLooper().quit();
    }

    private static void startTimerOut() {
        try {
            Runnable runnable2 = runnable;
            if (runnable2 != null) {
                mhandler.removeCallbacks(runnable2);
            }
            Runnable r0 = new Runnable() {
                public void run() {
                    if (LoopUtils.isRunning) {
                        LoopUtils.quitLoop();
                    }
                }
            };
            runnable = r0;
            mhandler.postDelayed(r0, 8000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void zipBackFile(final onZipFinishListener onzipfinishlistener) {
        try {
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass20 */

                public void run() {
                    try {
                        ArrayList arrayList = new ArrayList();
                        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick");
                        if (!file.exists()) {
                            file.mkdirs();
                        }
                        File file2 = new File(Environment.getExternalStorageDirectory() + "/XYClick/data");
                        if (!file2.exists()) {
                            file2.mkdirs();
                        }
                        File file3 = new File(Environment.getExternalStorageDirectory() + "/XYClick/temp");
                        if (!file3.exists()) {
                            file3.mkdirs();
                        }
                        arrayList.add(file2);
                        arrayList.add(file3);
                        final File file4 = new File(Environment.getExternalStorageDirectory() + "/XYClick", "XYClick.zip");
                        if (!file4.exists()) {
                            file4.createNewFile();
                        }
                        ZipUtilOld.zipFiles(arrayList, file4.getAbsoluteFile(), new ZipUtilOld.ZipListener() {
                            /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass20.AnonymousClass1 */

                            @Override // com.lmiot.xyclick.Util.ZipUtilOld.ZipListener
                            public void result(boolean z) {
                                if (z) {
                                    if (onzipfinishlistener != null) {
                                        onzipfinishlistener.result(file4.getAbsolutePath());
                                    }
                                } else if (onzipfinishlistener != null) {
                                    onzipfinishlistener.result("");
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mThread.start();
            mThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void zipFile(final File file, final onZipFinishListener onzipfinishlistener) {
        try {
            com.lmiot.xyclick.Util.FileUtils.checkFolder();
            Thread mThread = new Thread() {
                /* class com.lmiot.xyclick.Util.LoopUtils.AnonymousClass21 */

                public void run() {
                    try {
                        ArrayList arrayList = new ArrayList();
                        File file = new File(Environment.getExternalStorageDirectory() + "/XYClick/data");
                        if (!file.exists()) {
                            file.mkdirs();
                        }
                        File[] listFiles = file.listFiles();
                        if (listFiles != null) {
                            for (File file2 : listFiles) {
                                if (!file2.isDirectory() && file2.getName().endsWith(DataUtil.FILE_XYCLICK_DATA)) {
                                    arrayList.add(file2);
                                }
                            }
                        }
                        ZipUtilOld.zipFiles(arrayList, file.getAbsoluteFile(), new ZipUtilOld.ZipListener() {
                            @Override
                            public void result(boolean z) {
                                if (!z) {
                                    ToastUtil.err("文件压缩失败！");
                                } else if (onzipfinishlistener != null) {
                                    onzipfinishlistener.result(file.getAbsolutePath());
                                }
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mThread.start();
            mThread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
